package com.aiwhose.aiwhosesecurity.controller;

import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.aiwhose.aiwhosecore.bean.security.ShortMessage;
import com.aiwhose.aiwhosesecurity.service.ShortMessageService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import java.io.Serializable;
import java.util.List;

/**
 * 短信 控制层。
 *
 * @author 田国刚
 * @since 1.0.1
 */
@RestController
@Tag(name = "短信接口")
@RequestMapping("/shortMessage")
public class ShortMessageController {

    @Autowired
    private ShortMessageService shortMessageService;

    /**
     * 添加短信。
     *
     * @param shortMessage 短信
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(description="保存短信")
    public boolean save(@RequestBody @Parameter(description="短信")ShortMessage shortMessage) {
        return shortMessageService.save(shortMessage);
    }

    /**
     * 根据主键删除短信。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    @Operation(description="根据主键短信")
    public boolean remove(@PathVariable @Parameter(description="短信主键")Serializable id) {
        return shortMessageService.removeById(id);
    }

    /**
     * 根据主键更新短信。
     *
     * @param shortMessage 短信
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    @Operation(description="根据主键更新短信")
    public boolean update(@RequestBody @Parameter(description="短信主键")ShortMessage shortMessage) {
        return shortMessageService.updateById(shortMessage);
    }

    /**
     * 查询所有短信。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(description="查询所有短信")
    public List<ShortMessage> list() {
        return shortMessageService.list();
    }

    /**
     * 根据短信主键获取详细信息。
     *
     * @param id 短信主键
     * @return 短信详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(description="根据主键获取短信")
    public ShortMessage getInfo(@PathVariable Serializable id) {
        return shortMessageService.getById(id);
    }

    /**
     * 分页查询短信。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(description="分页查询短信")
    public Page<ShortMessage> page(@Parameter(description="分页信息")Page<ShortMessage> page) {
        return shortMessageService.page(page);
    }

}
